/* 

1 在公司里面 定义url 的一般重置成常量=大写
2 注释 jsdoc  注释风格 

*/


/**
 * 首页轮播图
 */
const HOMESWIPERDATA = "/home/swiperdata";

/**
 * 首页导航数据
 */
const HOMECATITEMS = "/home/catitems";


/**
 * 首页楼层数据
 */
const HOMEFLOORDATA = "/home/floordata";


/**
 * 商品分类
 */
const CATEGORIES = "/categories";

/**
 * 商品列表
 */
const GOODSSEARCH = "/goods/search";


/**
 * 商品详情
 */
const GOODSDETAIL = "/goods/detail";


/**
 * 获取token
 */
const WXLOGIN = "/users/wxlogin";

/**
 * 获取订单编号
 */
const ORDERCREATE = "/my/orders/create";

/**
 * 获取支付参数
 */
const REQUNIFIEDORDER = "/my/orders/req_unifiedorder";



// vm 相等于 组件中 this
const install = (Vue, vm) => {

  // 2 定义获取首页轮播图的函数
  const getHomeSwiperData = (params = {}) => vm.$u.get(HOMESWIPERDATA, params);

  const getHomeCatitems = (params = {}) => vm.$u.get(HOMECATITEMS, params);

  const getHomeFloordata = (params = {}) => vm.$u.get(HOMEFLOORDATA, params);

  const getCategories = (params = {}) => vm.$u.get(CATEGORIES, params);

  const getGoodsSearch = (params = {}) => vm.$u.get(GOODSSEARCH, params);

  const getGoodsDetail = (params = {}) => vm.$u.get(GOODSDETAIL, params);

  const getToken = (params = {}) => vm.$u.post(WXLOGIN, params);
  
  const getOrderNumber = (params = {}) => vm.$u.post(ORDERCREATE, params, { Authorization: vm.$store.state.token });

  const getPay = (params = {}) => vm.$u.post(REQUNIFIEDORDER, params, { Authorization: vm.$store.state.token });


  // 3 添加 vm.$u.api 对象上
  vm.$u.api = { getPay,getOrderNumber, getToken, getHomeSwiperData, getHomeCatitems, getHomeFloordata, getCategories, getGoodsSearch, getGoodsDetail };
}

export default {
  install
}